package com.homedo.core.common.exception;

import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author Harvey
 * @title: BizException
 * @package com.homedo.core.common.exception
 * @date 2018/1/19 14:37
 */
@Data
public class BizException extends RuntimeException{
    private Logger logger = LoggerFactory.getLogger(getClass());

    protected String error;
    protected int code;
    protected ResultData resultData;

    public BizException(ResultData resultData) {
        super(resultData.getMsg());
        this.resultData = resultData;
    }

    public BizException(String error) {
        super(error);
        this.code = Meta.CODE_500.getCode();
        this.error = error;
        this.resultData = new ResultData(new Meta(code, error));
    }

    public BizException(int code, String error) {
        super(error);
        this.code = code;
        this.error = error;
        this.resultData = new ResultData(new Meta(code, error));
    }

    public BizException(Meta meta) {
        super(meta.getMsg());
        this.code = meta.getCode();
        this.error = meta.getMsg();
        this.resultData = new ResultData(new Meta(code, error));
    }
    
}
